﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Security;


namespace BeniBastanYaratProject.Yonetim
{
    public partial class urundetay : System.Web.UI.Page
    {
        DBBaglantiDataContext DB = new DBBaglantiDataContext();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["uid"] != null)
            {

                var SORGU = (from x in DB.Urunlers where x.UrunID == int.Parse(Request.QueryString["uid"]) select x).SingleOrDefault();

                var SORGU2 = (from x in DB.Markalars where x.MarkaID == SORGU.MarkaID select x).SingleOrDefault();

                if (SORGU != null && SORGU2 != null)
                {

                    Image1.ImageUrl = SORGU.UrunResmiKucuk;
                    lblurunadi.Text = SORGU.UrunAdi;
                    lblmarkaadi.Text = SORGU2.MarkaFirmaAdi;
                    lblbedenno.Text = SORGU.BedenNo;
                    lblstok.Text = (SORGU.UrunStok).ToString();
                    lblaciklama.Text = SORGU.UrunAciklamasi;
                    lblfiyati.Text = (SORGU.UrunSatisFiyati).ToString("C");
                    sptBtn1.Tag = SORGU.UrunID;
                }
            }
            else
            {
                Response.Redirect("~/default.aspx");
            }



        }

        protected void sptBtn1_Click(object sender, EventArgs e)
        {
            if (Membership.GetUser() != null)
            {
                bool TransactionIsSuccessful = SepetIslemleri.SepeteEkle(Convert.ToInt32((sender as SepetButton.sptBtn).Tag), int.Parse("1"), new Guid(Membership.GetUser().ProviderUserKey.ToString()));
                if (TransactionIsSuccessful)
                {
                    ClientScript.RegisterStartupScript(typeof(Page), "Information", "alert(\"Urun Sepete Eklendi\");", true);
                }
                else
                {
                    ClientScript.RegisterStartupScript(typeof(Page), "Error", "alert(\"Urun Sepete Ekleme Başarısız..\");", true);
                }
            }
            else
            {
                Response.Redirect("~/Login.aspx");
            }
        }


    }
}